/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package window;

import dao.DAOFactory;
import services.empregado.EmpregadoServices;
import util.Const;

/**
 *
 * @author
 * PedroLZ
 */
public class DlgIncluirEmpregado extends BaseDlgDadosEmpregado 
{
	private static final String 
			SUCESSO_INCLUIR_EMPREGADO	= "SUCESSO_INCLUIR_EMPREGADO";
	
	public DlgIncluirEmpregado(java.awt.Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnCriar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        btnCriar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnCriar.setText("Criar");
        btnCriar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCriarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(426, Short.MAX_VALUE)
                .addComponent(btnCriar, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(165, 165, 165))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(493, Short.MAX_VALUE)
                .addComponent(btnCriar, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void btnCriarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCriarActionPerformed
		try {
			EmpregadoServices.inserirEmpregado( DAOFactory.getEmpregadoDAO(), getDadosEmpregado() );
			SupportWindow.mostrarMensagemSucesso( Const.getString(SUCESSO_INCLUIR_EMPREGADO) );
			SupportWindow.fecharDialogo( this );
			FrmListaEmpregados.atualizar();
		}
		catch (IllegalArgumentException ex){
			SupportWindow.mostrarMensagemInputIncorreta( ex );
		}
		catch (Exception ex) {
			SupportWindow.mostrarMensagemErro( ex );
		}
	}//GEN-LAST:event_btnCriarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCriar;
    // End of variables declaration//GEN-END:variables
}
